﻿using Bootstrap.Definition.Enums;
using Bootstrap.Helper;
using Bootstrap.Template.Tab;
using Bootstrap.Template.TemplateInnerItem;
using System.Collections.Generic;
using System.ComponentModel;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace Bootstrap.Control
{

    public class BootstrapTab : WebControl
    {
        #region Properties

        [PersistenceMode(PersistenceMode.InnerProperty)]
        public List<BootstrapTabItem> TabList { get; set; }

        public TabTypeEnum TabType { get; set; }

        [DefaultValue(true)]
        public bool ShowUnderLine { get; set; }

        #endregion

        #region Methods

        protected override void Render(System.Web.UI.HtmlTextWriter writer)
        {
            List<BootstrapTabTemplateInnerItem> tabList = new List<BootstrapTabTemplateInnerItem>();

            foreach (var item in this.TabList)
            {
                tabList.Add(new BootstrapTabTemplateInnerItem()
                {

                    Href = ValueHelper.GetDefaultValue<string>(item.Href, string.Empty),
                    Text = ValueHelper.GetDefaultValue<string>(item.Text, string.Empty),
                    IsActive = false,
                    Disabled = ValueHelper.GetDefaultValue<bool>(item.Disabled, false),
                    BadgedValue = ValueHelper.GetDefaultValue<string>(item.BadgedValue, string.Empty)

                });
            }

            BootstrapTabTemplateItem menu = new BootstrapTabTemplateItem()
            {
                ShowUnderLine = this.ShowUnderLine,
                TabTypeEnum = this.TabType
            };

            BootstrapTabTemplate template = new BootstrapTabTemplate(tabList, menu);

            writer.Write(template.TransformText());

        }

        #endregion
    }
}

